define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'project/index' + location.search,
                    add_url: 'project/add',
                    edit_url: 'project/edit',
					pay_url: 'project/pay',
                    del_url: 'project/del',
					view_url: 'project/view',
                    table: 'project',
                }
            });

            var table = $("#table");
			
			//当表格数据加载完成时
			table.on('load-success.bs.table', function (e, data) {
				//这里可以获取从服务端获取的JSON数据
				$("#title").html(data.year+'年度招标采购项目统计');
			});
			
			var queryparams = '';
			
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'serialnumber',
				sortOrder: 'asc',
				search: false,
				clickToSelect: false,
				searchFormVisible: true,
				rowStyle:function(row,index){
					var rowstyle = {css:{}};
					if(row.status != 3)
					{
						rowstyle.css.color = 'red';
					}
					if(index%2 == 0)
					{
						rowstyle.css['background-color'] = "#c3ebd1";
					}
					
					return rowstyle;
				},
				//fixedColumns: true,
				//fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        /* {field: 'id', title: __('序号'), sortable: true, searchable:false, visible:false, formatter: function(value, row, index){
							var pageNumber = table.bootstrapTable('getOptions').pageNumber;
							var pageSize = table.bootstrapTable('getOptions').pageSize;
							return ++index + (pageNumber-1)*pageSize;
						}}, */
						{field: 'serialnumber', title: __('序号'), searchable:false, operate: 'LIKE', sortable: true},
						{field: 'budgetyear', title: __('预算年度'), addclass: 'datetimepicker', defaultValue:Config.year?Config.year:'', extend: "data-date-format='YYYY' data-use-current=true", datetimeFormat:'YYYY', operate: 'LIKE'},
                        {field: 'name', title: __('项目名称'), operate: 'LIKE', align:'left', halign:'center', formatter: function(value, row, index){
							var html = value+' <a href="/admin/project/view/ids/'+row.id+'" class="btn btn-xs btn-warning btn-view btn-dialog" data-area="[&quot;30%&quot;,&quot;30%&quot;]" title="'+value+'" data-table-id="table"><i class="fa fa-eye"></i></a>';
							return html;
						}},
						{field: 'depart.name', title: __('采购科室'), searchable:true, operate: 'LIKE', visible:true, searchList:$.getJSON('project/departlist')},
						{field: 'contacter', title: __('联系人'), searchable:false, visible:false},
						{field: 'contactphone', title: __('联系电话'), searchable:false, visible:false},
						{field: 'procuretype', title: __('采购方式'), searchList: {1: __('公开招标'), 2: __('邀请招标'), 3: __('竞争性谈判'), 4: __('竞争性磋商'), 5: __('单一来源采购'), 6: __('询价'), 7: __('直接签订'), 8: __('其他')}, formatter: Table.api.formatter.normal, searchable:false, visible:false},
						{field: 'agentcompany', title: __('代理机构'), searchable:false, visible:false},
						{field: 'noticetime', title: __('公告发布时间'), formatter: Table.api.formatter.datetime, datetimeFormat:'YYYY-MM-DD', searchable:false, visible:false},
						{field: 'bidopentime', title: __('开标时间'), formatter: Table.api.formatter.datetime, datetimeFormat:'YYYY-MM-DD', searchable:false, visible:false},
                        {field: 'biddercompany', title: __('中标单位'), operate: 'LIKE', align:'left', halign:'center'},
						{field: 'fundingsource', title: __('资金来源'), searchable:false, visible:false},
						//{field: 'starttime', title: __('采购时间'), searchable:false, formatter: Table.api.formatter.datetime, datetimeFormat:'YYYY-MM-DD', extend: "data-locale='"+ JSON.stringify({format:'YYYY-MM-DD'})+"'"+" autocomplete='off'", operate: 'RANGE', addclass: 'datetimerange', sortable: true},
						//{field: 'paymenttime', title: __('付款日期'), searchable:false, formatter: Table.api.formatter.datetime, datetimeFormat:'YYYY-MM-DD', extend: "data-locale='"+ JSON.stringify({format:'YYYY-MM-DD'})+"'"+" autocomplete='off'", operate: 'RANGE', addclass: 'datetimerange', visible:false},
						//{field: 'payments.0.paymenttime', title: __('付款日期'), formatter: Table.api.formatter.datetime, datetimeFormat:'YYYY-MM-DD', extend: "data-locale='"+ JSON.stringify({format:'YYYY-MM-DD'})+"'"+" autocomplete='off'", operate: 'RANGE', addclass: 'datetimerange', sortable: true, searchable:false},
						{field: 'lastpaymenttime', title: __('付款日期'), formatter: Table.api.formatter.datetime, datetimeFormat:'YYYY-MM-DD', operate: 'RANGE', addclass: 'datetimerange', sortable: true, searchable:false},
						{field: 'totalmoney', title: __('预算金额'), searchable:false, visible:false, formatter: function(value, row, index){
							if(value < 1000) return value;
							if(Number.isInteger(value)) {
								return String(value).replace(/(?!^)(?=(\d{3})+$)/g, ',');
							}else{
								return String(value).replace(/(?!^)(?=(\d{3})+\.)/g, ',');
							}
						}},
						{field: 'biddermoney', title: __('合同金额'), sortable: true, searchable:false, formatter: function(value, row, index){
							if(value < 1000) return value;
							if(Number.isInteger(value)) {
								return String(value).replace(/(?!^)(?=(\d{3})+$)/g, ',');
							}else{
								return String(value).replace(/(?!^)(?=(\d{3})+\.)/g, ',');
							}
						}},
						{field: 'lawyerletter', title: __('律师审核意见书'), formatter: Table.api.formatter.file, searchable:false, visible:false},
						{field: 'contracttime', title: __('合同签订日期'), formatter: Table.api.formatter.datetime, datetimeFormat:'YYYY-MM-DD', searchable:false, visible:false},
						{field: 'endtime', title: __('完成时间'), formatter: Table.api.formatter.datetime, datetimeFormat:'YYYY-MM-DD', searchable:false, visible:false},
						{title: __('支付方式'), searchable:false, visible:false},
                        {field: 'paymenttimes', title: __('付款次数'), sortable: true, searchable:false},
						{field: 'payments.length', title: __('已付次数'), sortable: false, searchable:false},
						{field: 'status', title: __('项目进度'), searchList: {0: __('未开始'), 1: __('采购中'), 2: __('实施中'), 3: __('项目完成')},formatter: Table.api.formatter.normal},
						{field: 'execute_rate', title: __('项目执行进度'), searchable:false, visible:false},
						{field: 'admin.nickname', title: __('录入人'), searchable:false, operate: 'LIKE'},
						{field: 'warranty_period', title: __('质保期限'), searchable:false, visible:false},
						{field: 'supervision_depart', title: __('监理单位'), searchable:false, visible:false},
						{field: 'supervision_report', title: __('监理报告'), formatter: Table.api.formatter.file, searchable:false, visible:false},
						{field: 'audit_depart', title: __('工程审计单位'), searchable:false, visible:false},
						{field: 'audit_report', title: __('工程审计报告'), formatter: Table.api.formatter.file, searchable:false, visible:false},
						{field: 'checkreport', title: __('验收资料'), formatter: Table.api.formatter.file, searchable:false, visible:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons:[
								/* {
									name: 'view',
									title: __('查看'),
									text:__('查看'),
									classname: 'btn btn-xs btn-warning btn-dialog',
									url: $.fn.bootstrapTable.defaults.extend.view_url,
									extend:'data-area=\'["30%","30%"]\''
								},
								{
									name: 'pay',
									title: __('付款'),
									text:__('付款'),
									classname: 'btn btn-xs btn-primary btn-dialog',
									url: $.fn.bootstrapTable.defaults.extend.pay_url,
									extend:'data-area=\'["55%","70%"]\''
								}, */
								{
									name: 'edit',
									icon: 'fa fa-pencil',
									title: __('Edit'),
									text: __('Edit'),
									extend: 'data-toggle="tooltip" data-container="body"',
									classname: 'btn btn-xs btn-success btn-editone',
									extend:'data-area=\'["55%","70%"]\''
								}
							],formatter: Table.api.formatter.operate}
                    ]
                ],
				queryParams:function (params) {
					queryparams = params;
					return params;
				}
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
			
			$(document).on('click', '.btn-pay', function () {
				var that = this;
				var ids = Table.api.selectedids(table);
				if (ids.length > 10) {
					return;
				}
				var title = $(that).data('title') || $(that).attr("title") || __('付款');
				var data = $(that).data() || {};
				delete data.title;
				//循环弹出多个编辑框
				$.each(Table.api.selecteddata(table), function (index, row) {
					var url = $.fn.bootstrapTable.defaults.extend.pay_url;
					row = $.extend({}, row ? row : {}, {ids: row['id']});
					url = Table.api.replaceurl(url, row, table);
					Fast.api.open(url, typeof title === 'function' ? title.call(table, row) : title, data);
				});
			});
			
			// 续费
            $(document).on('click', '.btn-renew', function () {
                var ids = Table.api.selectedids(table);
				Layer.confirm(
                        __('你确定要续费吗?'),
                        {icon: 3, title: __('Warning'), shadeClose: true, btn: [__('OK'), __('Cancel')]},
                        function (index) {
                            Fast.api.ajax({
								url: "project/renew",
								type: "post",
								data: {ids: ids.join(',')},
							}, function () {
								table.bootstrapTable('refresh', {});
								Layer.close(index);
							});
                        }
                    );
            });
			
			// 导出
            $(document).on('click', '.btn-export', function () {
					var filter = queryparams.filter;
					var op = queryparams.op;
					var sort = queryparams.sort;
					var order = queryparams.order;
					/* table.one('post-body.bs.table', function () {
						require(['tableexport'], function () {
							table.tableExport($.extend({}, $.fn.bootstrapTable.defaults.exportOptions, {
								type: 'excel',
								escape: false
							}));
						});
						table.bootstrapTable('togglePagination', {});
					});
					table.bootstrapTable('togglePagination', {}); */
					location.href="export?sort="+sort+"&order="+order+"&filter="+filter+"&op="+op;
			});
			
			$('.commonsearch-table .form-group').each(function(){
				$(this).addClass('col-lg-2');
			});
        },
		implementing: function () {
			// 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'project/implementing' + location.search,
					pay_url: 'project/pay',
                    table: 'project',
                }
            });

            var table = $("#table");
			
			//当表格数据加载完成时
			table.on('load-success.bs.table', function (e, data) {
				//这里可以获取从服务端获取的JSON数据
				$("#title").html(data.year+'年度实施进行中项目统计');
			});
			
			var queryparams = '';
			
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'serialnumber',
				sortOrder: 'asc',
				search: false,
				searchFormVisible: true,
				rowStyle:function(row,index){
					var rowstyle = {css:{}};
					if(index%2 == 0)
					{
						rowstyle.css['background-color'] = "#c3ebd1";
					}
					
					return rowstyle;
				},
				fixedColumns: true,
				clickToSelect: false,
				fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
						{field: 'serialnumber', title: __('序号'), searchable:false, operate: 'LIKE', sortable: true},
						{field: 'budgetyear', title: __('预算年度'), addclass: 'datetimepicker', defaultValue:Config.year?Config.year:'', extend: "data-date-format='YYYY' data-use-current=true", datetimeFormat:'YYYY', operate: 'LIKE', visible:false},
                        {field: 'name', title: __('项目名称'), operate: 'LIKE', align:'left', halign:'center', formatter: function(value, row, index){
							var html = value+' <a href="/admin/project/paymentview/ids/'+row.id+'" class="btn btn-xs btn-warning btn-view btn-dialog" data-area="[&quot;30%&quot;,&quot;40%&quot;]" title="'+value+'" data-table-id="table"><i class="fa fa-eye"></i></a>';
							return html;
						}},
						{field: 'totalmoney', title: __('预算金额'), searchable:false, visible:true, formatter: function(value, row, index){
							if(value < 1000) return value;
							if(Number.isInteger(value)) {
								return String(value).replace(/(?!^)(?=(\d{3})+$)/g, ',');
							}else{
								return String(value).replace(/(?!^)(?=(\d{3})+\.)/g, ',');
							}
						}},
						{field: 'biddermoney', title: __('合同金额'), sortable: true, searchable:false, formatter: function(value, row, index){
							if(value < 1000) return value;
							if(Number.isInteger(value)) {
								return String(value).replace(/(?!^)(?=(\d{3})+$)/g, ',');
							}else{
								return String(value).replace(/(?!^)(?=(\d{3})+\.)/g, ',');
							}
						}},
						{field: 'payedmoney', title: __('已支付金额'), searchable:false, visible:true},
						{field: 'execute_rate', title: __('支付比例'), searchable:false, visible:true},
						{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons:[
								{
									name: 'pay',
									title: __('付款'),
									text:__('付款'),
									classname: 'btn btn-xs btn-primary btn-dialog',
									url: $.fn.bootstrapTable.defaults.extend.pay_url,
									extend:'data-area=\'["55%","70%"]\''
								}
							],formatter: Table.api.formatter.operate}
                    ]
                ],
				queryParams:function (params) {
					queryparams = params;
					return params;
				}
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
		},	
		buying: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'project/buying' + location.search,
                    edit_url: 'project/edit',
                    table: 'project',
                }
            });

            var table = $("#table");
			
			//当表格数据加载完成时
			table.on('load-success.bs.table', function (e, data) {
				//这里可以获取从服务端获取的JSON数据
				if(data.year) $("#title").html(data.year+'年度采购进行中项目统计');
				
				$('.btn-edittwo').on('click', function(){
					var id = $(this).data('id');
					var field = $(this).data('field');
					Fast.api.open('project/supple/ids/'+id+'?dialog=1&field='+field, '完善项目', {area:["30%","40%"]});
				});
			});
			
			var queryparams = '';
			
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'serialnumber',
				sortOrder: 'asc',
				search: false,
				searchFormVisible: true,
				rowStyle:function(row,index){
					var rowstyle = {css:{}};
					if(index%2 == 0)
					{
						rowstyle.css['background-color'] = "#c3ebd1";
					}
					
					return rowstyle;
				},
				fixedColumns: true,
				clickToSelect: false,
				fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
						{field: 'serialnumber', title: __('序号'), searchable:false, operate: 'LIKE', sortable: true},
						{field: 'budgetyear', title: __('预算年度'), addclass: 'datetimepicker', defaultValue:Config.year?Config.year:'', extend: "data-date-format='YYYY' data-use-current=true", datetimeFormat:'YYYY', operate: 'LIKE', visible:false},
                        {field: 'name', title: __('项目名称'), operate: 'LIKE', align:'left', halign:'center'},
						{field: 'agentcompany', title: __('代理公司'), searchable:false, visible:true, formatter:function(value, row, index){
							if(row.procuretype == '')
							{
								return '请选择采购方式';
							}
							else if(row.procuretype == 7)
							{
								return '无';
							}
							else if(value)
							{
								return '<span class="btn btn-xs btn-success">是</span>';
							}
							else
							{
								var html = '<a href="javascript:;" class="btn btn-xs btn-danger btn-edittwo" data-id="'+row.id+'" data-field="agentcompany"> 否</a>';
								return html;
							}
						}},
						{field: 'biddercompany', title: __('中标单位'), searchable:false, visible:true, formatter:function(value, row, index){
							if(row.procuretype == '')
							{
								return '请选择采购方式';
							}
							else if(value)
							{
								return '<span class="btn btn-xs btn-success">是</span>';
							}
							else
							{
								var html = '<a href="javascript:;" class="btn btn-xs btn-danger btn-edittwo" data-id="'+row.id+'" data-field="biddercompany"> 否</a>';
								return html;
							}
						}},
						{field: 'noticetime', title: __('公告发布时间'), formatter: function(value, row, index){
							if(row.procuretype == '')
							{
								return '请选择采购方式';
							}
							else if(row.procuretype == 7)
							{
								return '无';
							}
							else if(value)
							{
								return '<span class="btn btn-xs btn-success">是</span>';
							}
							else
							{
								var html = '<a href="javascript:;" class="btn btn-xs btn-danger btn-edittwo" data-id="'+row.id+'" data-field="noticetime"> 否</a>';
								return html;
							}
						}, searchable:false, visible:true},
						{field: 'bidopentime', title: __('开标时间'), formatter: function(value, row, index){
							if(row.procuretype == '')
							{
								return '请选择采购方式';
							}
							else if(row.procuretype == 7)
							{
								return '无';
							}
							else if(value)
							{
								return '<span class="btn btn-xs btn-success">是</span>';
							}
							else
							{
								var html = '<a href="javascript:;" class="btn btn-xs btn-danger btn-edittwo" data-id="'+row.id+'" data-field="bidopentime"> 否</a>';
								return html;
							}
						}, searchable:false, visible:true},
                        {field: 'contracttime', title: __('合同签订时间'), formatter: function(value, row, index){
							if(row.procuretype == '')
							{
								return '请选择采购方式';
							}
							else if(value)
							{
								return '<span class="btn btn-xs btn-success">是</span>';
							}
							else
							{
								var html = '<a href="javascript:;" class="btn btn-xs btn-danger btn-edittwo" data-id="'+row.id+'" data-field="contracttime"> 否</a>';
								return html;
							}
						}, searchable:false},
						{field: 'bidding', title: __('招标文件'), formatter: function(value, row, index){
							if(row.procuretype == '')
							{
								return '请选择采购方式';
							}
							else if(row.procuretype == 7 || row.nobidding == 1)
							{
								return '无';
							}
							else if(value)
							{
								return '<span class="btn btn-xs btn-success">是</span>';
							}
							else
							{
								var html = '<a href="javascript:;" class="btn btn-xs btn-danger btn-edittwo" data-id="'+row.id+'" data-field="bidding"> 否</a>';
								return html;
							}
						}, searchable:false, visible:true},
						{field: 'rfp', title: __('投标文件'), formatter: function(value, row, index){
							if(row.procuretype == '')
							{
								return '请选择采购方式';
							}
							else if(row.procuretype == 7 || row.norfp == 1)
							{
								return '无';
							}
							else if(value)
							{
								return '<span class="btn btn-xs btn-success">是</span>';
							}
							else
							{
								var html = '<a href="javascript:;" class="btn btn-xs btn-danger btn-edittwo" data-id="'+row.id+'" data-field="rfp"> 否</a>';
								return html;
							}
						}, searchable:false, visible:true},
						{field: 'acceptance', title: __('中标通知书'), formatter: function(value, row, index){
							if(row.procuretype == '')
							{
								return '请选择采购方式';
							}
							else if(row.procuretype == 7 || row.noacceptance == 1)
							{
								return '无';
							}
							else if(value)
							{
								return '<span class="btn btn-xs btn-success">是</span>';
							}
							else
							{
								var html = '<a href="javascript:;" class="btn btn-xs btn-danger btn-edittwo" data-id="'+row.id+'" data-field="acceptance"> 否</a>';
								return html;
							}
						}, searchable:false, visible:true},
						{field: 'lawyerletter', title: __('律师审核意见书'), formatter: function(value, row, index){
							if(row.procuretype == '')
							{
								return '请选择采购方式';
							}
							else if(row.procuretype == 7 || row.nolawyerletter == 1)
							{
								return '无';
							}
							else if(value)
							{
								return '<span class="btn btn-xs btn-success">是</span>';
							}
							else
							{
								var html = '<a href="javascript:;" class="btn btn-xs btn-danger btn-edittwo" data-id="'+row.id+'" data-field="lawyerletter"> 否</a>';
								return html;
							}
						}, searchable:false, visible:true},
						{field: 'contract', title: __('中标合同'), formatter: function(value, row, index){
							if(row.procuretype == '')
							{
								return '请选择采购方式';
							}
							else if(row.procuretype == 7 || row.nocontract == 1)
							{
								return '无';
							}
							else if(value)
							{
								return '<span class="btn btn-xs btn-success">是</span>';
							}
							else
							{
								var html = '<a href="javascript:;" class="btn btn-xs btn-danger btn-edittwo" data-id="'+row.id+'" data-field="contract"> 否</a>';
								return html;
							}
						}, searchable:false, visible:true},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons:[
								{
									name: 'edit',
									icon: 'fa fa-pencil',
									title: __('Edit'),
									text: __('Edit'),
									extend: 'data-toggle="tooltip" data-container="body"',
									classname: 'btn btn-xs btn-success btn-editone',
									extend:'data-area=\'["55%","70%"]\''
								}
							],formatter: Table.api.formatter.operate}
                    ]
                ],
				queryParams:function (params) {
					queryparams = params;
					return params;
				}
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
			$(document).on("change", "#procuretype", function () {
                    var value = $(this).val();
					if(value == 1 || value == 2 || value == 3 || value == 4 || value == 5 || value == 6 || value == 8)
					{
						$('#agentcompany').show();
						$('#biddercompany').show();
						$('#noticetime').show();
						$('#contracttime').show();
						$('#bidding').show();
						$('#rfp').show();
						$('#acceptance').show();
						$('#lawyerletter').show();
						$('#contract').show();
					}
					else if(value == 7)
					{
						$('#agentcompany').hide();
						$('#biddercompany').show();
						$('#lawyerletter').show();
						$('#contract').show();
						$('#contracttime').show();
						$('#noticetime').hide();
						$('#bidding').hide();
						$('#rfp').hide();
						$('#acceptance').hide();
					}
					else
					{
						$('#agentcompany').hide();
						$('#biddercompany').hide();
						$('#lawyerletter').hide();
						$('#contract').hide();
						$('#contracttime').hide();
						$('#noticetime').hide();
						$('#bidding').hide();
						$('#rfp').hide();
						$('#acceptance').hide();
					}
			});
			
			$(document).on("change", "#c-paymenttimes", function () {
				var value = $(this).val();
				for(var i=1; i<=10; i++)
				{
					$('#paymentimes-'+i).hide();
				}
				for(var i=1; i<=value; i++)
				{
					$('#paymentimes-'+i).show();
				}
            });
			
			$(document).on("change", "input[name='row[supervise]']", function () {
				var isChecked = $(this).is(':checked');
				if(isChecked==true)
				{
					$('#supervise').show();
				}
				else
				{
					$('#supervise').hide();
				}
			});
			
			$(document).on("change", ".paymentimes input[type='radio']", function () {
				var biddermoney = $('#c-biddermoney').val();
				biddermoney = Number(biddermoney.replaceAll(',', ''));
				var leiji_rate = '0.00';
				if(biddermoney != 0)
				{
					var leiji_pay_money = 0;
					$('.paymentimes').each(function(){
						var pay_money = $(this).find('.paymentmoney').val();
						pay_money = Number(pay_money.replaceAll(',', ''));
						var paymentstatus = $(this).find('input[type="radio"]:checked').val();
						if(pay_money!=0 && paymentstatus==1)
						{
							leiji_pay_money += parseFloat(pay_money);
						}
					});
					leiji_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
				}
				$('.execute_rate').html(leiji_rate+'%');
			});
			
			$(document).on('blur',".paymentmoney", function(){
				var biddermoney = $('#c-biddermoney').val();
				biddermoney = Number(biddermoney.replaceAll(',', ''));
				var pay_money = $(this).val();
				pay_money = Number(pay_money.replaceAll(',', ''));
				
				var uppder_pay_money = convertCurrency(pay_money);
				$(this).parents('.paymentimes').find('.upper-paymentmoney').html(uppder_pay_money);
				
				var pay_rate = '0.00';
				var leiji_rate = '0.00';
				if(biddermoney != 0)
				{
					pay_rate = (pay_money*100/biddermoney).toFixed(2);
					
					var leiji_pay_money = 0;
					$('.paymentimes').each(function(){
						var pay_money = $(this).find('.paymentmoney').val();
						pay_money = Number(pay_money.replaceAll(',', ''));
						var paymentstatus = $(this).find('input[type="radio"]:checked').val();
						if(paymentstatus==1)
						{
							leiji_pay_money += parseFloat(pay_money);
							//var leiji_pay_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
							//$(this).find('.total-pay-rate').html(leiji_pay_rate+'%');
						}
					});
					
					leiji_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
				}
				
				$(this).parents('.paymentimes').find('.pay-rate').html(pay_rate+'%');
				$('.execute_rate').html(leiji_rate+'%');
			});
			
			$(document).on('blur','input[name="row[totalmoney]"]', function(){
				var totalmoney = $(this).val();
				totalmoney = Number(totalmoney.replaceAll(',', ''));
				
				var uppder_totalmoney = convertCurrency(totalmoney);
				$('#c-upcase_totalmoney').html(uppder_totalmoney);
			});
			
			$(document).on('blur','input[name="row[biddermoney]"]', function(){
				var biddermoney = $(this).val();
				biddermoney = Number(biddermoney.replaceAll(',', ''));
				
				var uppder_biddermoney = convertCurrency(biddermoney);
				$('#c-upcase_biddermoney').html(uppder_biddermoney);
				
				var leiji_pay_money = 0;
				$('.paymentimes').each(function(){
					var pay_money = $(this).find('.paymentmoney').val();
					pay_money = Number(pay_money.replaceAll(',', ''));
					var paymentstatus = $(this).find('input[type="radio"]:checked').val();

					var pay_rate = '0.00';
					//var leiji_pay_rate = '0.00';
					if(biddermoney)
					{
						pay_rate = (pay_money*100/biddermoney).toFixed(2);
						
						if(paymentstatus==1) leiji_pay_money += parseFloat(pay_money);
						//leiji_pay_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
					}
					$(this).find('.pay-rate').html(pay_rate+'%');
					//$(this).find('.total-pay-rate').html(leiji_pay_rate+'%');
				});
				
				var execute_rate = '0.00';
				if(biddermoney)
				{
					execute_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
				}
				$('.execute_rate').html(execute_rate+'%');
			});
			
			$(document).on('blur','input[step="0.01"]', function(){
				var money = $(this).val();
				money = Number(money.replaceAll(',', ''));
				money = money.toFixed(2);
				if(money >= 1000)
				{
					money = String(money).replace(/(?!^)(?=(\d{3})+\.)/g, ',');
				}
							
				$(this).val(money);
			});
			
			$(document).on('change','select[name="row[procuredepart]"]',function(){
				var depart = $('.filter-option-inner-inner').html();
				depart = depart.replace('├ ','');
				depart = depart.replace('└ ','');
				$('select[name="row[procuredepart]"]').parent().find('.filter-option-inner-inner').html(depart);
			});
			
			$(document).on('click','button[type="reset"]', function(){
				var index = parent.Layer.getFrameIndex(window.name);
				parent.Layer.close(index);
			});	
			
            Form.api.bindevent($("form[role=form]"), function(data, ret){
				location.reload();
				Backend.api.addtabs(ret.url, '项目列表');
			});
        },
		supple: function () {
			$(document).on('click','button[type="reset"]', function(){
				var index = parent.Layer.getFrameIndex(window.name);
				parent.Layer.close(index);
			});
			Controller.api.bindevent();
		},
        edit: function () {
			$(document).on("change", "#procuretype", function () {
                    var value = $(this).val();
					if(value == 1 || value == 2 || value == 3 || value == 4 || value == 5 || value == 6 || value == 8)
					{
						$('#agentcompany').show();
						$('#biddercompany').show();
						$('#noticetime').show();
						$('#contracttime').show();
						$('#bidding').show();
						$('#rfp').show();
						$('#acceptance').show();
						$('#lawyerletter').show();
						$('#contract').show();
					}
					else if(value == 7)
					{
						$('#agentcompany').hide();
						$('#biddercompany').show();
						$('#lawyerletter').show();
						$('#contract').show();
						$('#contracttime').show();
						$('#noticetime').hide();
						$('#bidding').hide();
						$('#rfp').hide();
						$('#acceptance').hide();
					}
					else
					{
						$('#agentcompany').hide();
						$('#biddercompany').hide();
						$('#lawyerletter').hide();
						$('#contract').hide();
						$('#contracttime').hide();
						$('#noticetime').hide();
						$('#bidding').hide();
						$('#rfp').hide();
						$('#acceptance').hide();
					}
			});
			
			$(document).on("change", "#c-paymenttimes", function () {
                    var value = $(this).val();
					for(var i=1; i<=10; i++)
					{
						$('#paymentimes-'+i).hide();
					}
					for(var i=1; i<=value; i++)
					{
						$('#paymentimes-'+i).show();
					}
                });
			
			$(document).on("change", "input[name='row[supervise]']", function () {
				var isChecked = $(this).is(':checked');
				if(isChecked==true)
				{
					$('#supervise').show();
				}
				else
				{
					$('#supervise').hide();
				}
			});
			
			$(document).on("change", ".paymentimes input[type='radio']", function () {
				var biddermoney = $('#c-biddermoney').val();
				biddermoney = Number(biddermoney.replaceAll(',', ''));
				var leiji_rate = '0.00';
				if(biddermoney != 0)
				{
					var leiji_pay_money = 0;
					$('.paymentimes').each(function(){
						var pay_money = $(this).find('.paymentmoney').val();
						pay_money = Number(pay_money.replaceAll(',', ''));
						var paymentstatus = $(this).find('input[type="radio"]:checked').val();
						if(pay_money!=0 && paymentstatus==1)
						{
							leiji_pay_money += parseFloat(pay_money);
						}
					});
					leiji_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
				}
				$('.execute_rate').html(leiji_rate+'%');
			});
				
			$(document).on('blur',".paymentmoney", function(){
				var biddermoney = $('#c-biddermoney').val();
				biddermoney = Number(biddermoney.replaceAll(',', ''));
				var pay_money = $(this).val();
				pay_money = Number(pay_money.replaceAll(',', ''));
				
				var uppder_pay_money = convertCurrency(pay_money);
				$(this).parents('.paymentimes').find('.upper-paymentmoney').html(uppder_pay_money);
				
				var pay_rate = '0.00';
				var leiji_rate = '0.00';
				if(biddermoney != 0)
				{
					pay_rate = (pay_money*100/biddermoney).toFixed(2);
					
					var leiji_pay_money = 0;
					$('.paymentimes').each(function(){
						var pay_money = $(this).find('.paymentmoney').val();
						pay_money = Number(pay_money.replaceAll(',', ''));
						var paymentstatus = $(this).find('input[type="radio"]:checked').val();
						if(paymentstatus==1)
						{
							leiji_pay_money += parseFloat(pay_money);
							//var leiji_pay_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
							//$(this).find('.total-pay-rate').html(leiji_pay_rate+'%');
						}
					});
					
					leiji_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
				}
				
				$(this).parents('.paymentimes').find('.pay-rate').html(pay_rate+'%');
				$('.execute_rate').html(leiji_rate+'%');
			});
			
			$(document).on('blur','input[name="row[totalmoney]"]', function(){
				var totalmoney = $(this).val();
				totalmoney = Number(totalmoney.replaceAll(',', ''));
				
				var uppder_totalmoney = convertCurrency(totalmoney);
				$('#c-upcase_totalmoney').html(uppder_totalmoney);
			});
			
			$(document).on('blur','input[name="row[biddermoney]"]', function(){
				var biddermoney = $(this).val();
				biddermoney = Number(biddermoney.replaceAll(',', ''));
				
				var uppder_biddermoney = convertCurrency(biddermoney);
				$('#c-upcase_biddermoney').html(uppder_biddermoney);
				
				var leiji_pay_money = 0;
				$('.paymentimes').each(function(){
					var pay_money = $(this).find('.paymentmoney').val();
					pay_money = Number(pay_money.replaceAll(',', ''));
					var paymentstatus = $(this).find('input[type="radio"]:checked').val();

					var pay_rate = '0.00';
					//var leiji_pay_rate = '0.00';
					if(biddermoney)
					{
						pay_rate = (pay_money*100/biddermoney).toFixed(2);
					
						if(paymentstatus==1) leiji_pay_money += parseFloat(pay_money);
						//leiji_pay_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
					}
					$(this).find('.pay-rate').html(pay_rate+'%');
					//$(this).find('.total-pay-rate').html(leiji_pay_rate+'%');
				});
				
				var execute_rate = '0.00';
				if(biddermoney)
				{
					execute_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
				}
				$('.execute_rate').html(execute_rate+'%');
			});
			
			$(document).on('change','select[name="row[procuredepart]"]',function(){
				var depart = $('.filter-option-inner-inner').html();
				depart = depart.replace('├ ','');
				depart = depart.replace('└ ','');
				$('select[name="row[procuredepart]"]').parent().find('.filter-option-inner-inner').html(depart);
			});
			
			$(document).on('blur','input[step="0.01"]', function(){
				var money = $(this).val();
				money = Number(money.replaceAll(',', ''));
				money = money.toFixed(2);
				if(money >= 1000)
				{
					money = String(money).replace(/(?!^)(?=(\d{3})+\.)/g, ',');
				}
							
				$(this).val(money);
			});
			
			$(document).on('click','button[type="reset"]', function(){
				var index = parent.Layer.getFrameIndex(window.name);
				parent.Layer.close(index);
			});	
			
            Controller.api.bindevent();
			
			setTimeout(function(){
				var depart = $('select[name="row[procuredepart]"]').parent().find('.filter-option-inner-inner').html();
				depart = depart.replace('├ ','');
				depart = depart.replace('└ ','');
				$('select[name="row[procuredepart]"]').parent().find('.filter-option-inner-inner').html(depart);
			}, 1000);
			
			
        },
		pay: function () {
			$(document).on("change", "#c-paymenttimes", function () {
                    var value = $(this).val();
					for(var i=1; i<=10; i++)
					{
						$('#paymentimes-'+i).hide();
					}
					for(var i=1; i<=value; i++)
					{
						$('#paymentimes-'+i).show();
					}
                });
			
			$(document).on("change", ".paymentimes input[type='radio']", function () {
				var biddermoney = $('#c-biddermoney').val();
				biddermoney = Number(biddermoney.replaceAll(',', ''));
				var leiji_rate = '0.00';
				if(biddermoney != 0)
				{
					var leiji_pay_money = 0;
					$('.paymentimes').each(function(){
						var pay_money = $(this).find('.paymentmoney').val();
						pay_money = Number(pay_money.replaceAll(',', ''));
						var paymentstatus = $(this).find('input[type="radio"]:checked').val();
						if(pay_money!=0 && paymentstatus==1)
						{
							leiji_pay_money += parseFloat(pay_money);
						}
					});
					leiji_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
				}
				$('.execute_rate').html(leiji_rate+'%');
			});
			
			$(document).on('blur',".paymentmoney", function(){
				var biddermoney = $('#c-biddermoney').val();
				biddermoney = Number(biddermoney.replaceAll(',', ''));
				var pay_money = $(this).val();
				pay_money = Number(pay_money.replaceAll(',', ''));
				
				var uppder_pay_money = convertCurrency(pay_money);
				$(this).parents('.paymentimes').find('.upper-paymentmoney').html(uppder_pay_money);
				
				var pay_rate = '0.00';
				var leiji_rate = '0.00';
				if(biddermoney != 0)
				{
					pay_rate = (pay_money*100/biddermoney).toFixed(2);
					
					var leiji_pay_money = 0;
					$('.paymentimes').each(function(){
						var pay_money = $(this).find('.paymentmoney').val();
						pay_money = Number(pay_money.replaceAll(',', ''));
						var paymentstatus = $(this).find('input[type="radio"]:checked').val();
						if(paymentstatus==1)
						{
							leiji_pay_money += parseFloat(pay_money);
							//var leiji_pay_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
							//$(this).find('.total-pay-rate').html(leiji_pay_rate+'%');
						}
					});
					
					leiji_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
				}
				
				$(this).parents('.paymentimes').find('.pay-rate').html(pay_rate+'%');
				$('.execute_rate').html(leiji_rate+'%');
			});
			
			$(document).on('blur','input[name="row[totalmoney]"]', function(){
				var totalmoney = $(this).val();
				totalmoney = Number(totalmoney.replaceAll(',', ''));
				
				var uppder_totalmoney = convertCurrency(totalmoney);
				$('#c-upcase_totalmoney').html(uppder_totalmoney);
			});
			
			$(document).on('blur','input[name="row[biddermoney]"]', function(){
				var biddermoney = $(this).val();
				biddermoney = Number(biddermoney.replaceAll(',', ''));
				
				var uppder_biddermoney = convertCurrency(biddermoney);
				$('#c-upcase_biddermoney').html(uppder_biddermoney);
				
				var leiji_pay_money = 0;
				$('.paymentimes').each(function(){
					var pay_money = $(this).find('.paymentmoney').val();
					pay_money = Number(pay_money.replaceAll(',', ''));
					var paymentstatus = $(this).find('input[type="radio"]:checked').val();

					var pay_rate = '0.00';
					//var leiji_pay_rate = '0.00';
					if(biddermoney)
					{
						pay_rate = (pay_money*100/biddermoney).toFixed(2);
					
						if(paymentstatus==1) leiji_pay_money += parseFloat(pay_money);
						//leiji_pay_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
					}
					$(this).find('.pay-rate').html(pay_rate+'%');
					//$(this).find('.total-pay-rate').html(leiji_pay_rate+'%');
				});
				
				var execute_rate = '0.00';
				if(biddermoney)
				{
					execute_rate = (leiji_pay_money*100/biddermoney).toFixed(2);
				}
				$('.execute_rate').html(execute_rate+'%');
			});
			
			$(document).on('blur','input[step="0.01"]', function(){
				var money = $(this).val();
				money = Number(money.replaceAll(',', ''));
				money = money.toFixed(2);
				if(money >= 1000)
				{
					money = String(money).replace(/(?!^)(?=(\d{3})+\.)/g, ',');
				}
							
				$(this).val(money);
			});
			
			$(document).on('click','button[type="reset"]', function(){
				var index = parent.Layer.getFrameIndex(window.name);
				parent.Layer.close(index);
			});
			
            Controller.api.bindevent();
        },
		view: function () {
			$(document).on('click','button[type="reset"]', function(){
				var index = parent.Layer.getFrameIndex(window.name);
				parent.Layer.close(index);
			});
		},
		paymentview: function () {
			$(document).on('click','button[type="reset"]', function(){
				var index = parent.Layer.getFrameIndex(window.name);
				parent.Layer.close(index);
			});
		},
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
	
	function convertCurrency(money) { 
	  //汉字的数字  
	  var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');  
	  //基本单位  
	  var cnIntRadice = new Array('', '拾', '佰', '仟');  
	  //对应整数部分扩展单位  
	  var cnIntUnits = new Array('', '万', '亿', '兆');  
	  //对应小数部分单位  
	  var cnDecUnits = new Array('角', '分', '毫', '厘');  
	  //整数金额时后面跟的字符  
	  var cnInteger = '整';  
	  //整型完以后的单位  
	  var cnIntLast = '元';  
	  //最大处理的数字  
	  var maxNum = 999999999999999.9999;  
	  //金额整数部分  
	  var integerNum;  
	  //金额小数部分  
	  var decimalNum;  
	  //输出的中文金额字符串  
	  var chineseStr = '';  
	  //分离金额后用的数组，预定义  
	  var parts;  
	  if (money == '') { return ''; }  
	  money = parseFloat(money);  
	  if (money >= maxNum) {  
		//超出最大处理数字  
		return '';  
	  }  
	  if (money == 0) {  
		chineseStr = cnNums[0] + cnIntLast + cnInteger;  
		return chineseStr;  
	  }  
	  //转换为字符串  
	  money = money.toString();  
	  if (money.indexOf('.') == -1) {  
		integerNum = money;  
		decimalNum = '';  
	  } else {  
		parts = money.split('.');  
		integerNum = parts[0];  
		decimalNum = parts[1].substr(0, 4);  
	  }  
	  //获取整型部分转换  
	  if (parseInt(integerNum, 10) > 0) {  
		var zeroCount = 0;  
		var IntLen = integerNum.length;  
		for (var i = 0; i < IntLen; i++) {  
		  var n = integerNum.substr(i, 1);  
		  var p = IntLen - i - 1;  
		  var q = p / 4;  
		  var m = p % 4;  
		  if (n == '0') {  
			zeroCount++;  
		  } else {  
			if (zeroCount > 0) {  
			  chineseStr += cnNums[0];  
			}  
			//归零  
			zeroCount = 0;  
			chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];  
		  }  
		  if (m == 0 && zeroCount < 4) {  
			chineseStr += cnIntUnits[q];  
		  }  
		}  
		chineseStr += cnIntLast;  
	  }  
	  //小数部分  
	  if (decimalNum != '') {  
		var decLen = decimalNum.length;  
		for (var i = 0; i < decLen; i++) {  
		  var n = decimalNum.substr(i, 1);  
		  if (n != '0') {  
			chineseStr += cnNums[Number(n)] + cnDecUnits[i];  
		  }  
		}  
	  }  
	  if (chineseStr == '') {  
		chineseStr += cnNums[0] + cnIntLast + cnInteger;  
	  } else if (decimalNum == '') {  
		chineseStr += cnInteger;  
	  }
	  return chineseStr;  
	} 

    return Controller;
});